package cn.enilu.guns.bean.entity.door;


import cn.enilu.guns.utils.StringUtils;
import lombok.Data;
import cn.enilu.guns.bean.entity.BaseEntity;
import org.hibernate.annotations.Table;
import javax.persistence.Column;
import javax.persistence.Entity;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.EntityListeners;

@Entity(name="t_time_info")
@Table(appliesTo = "t_time_info",comment = "时间段信息")
@Data
@EntityListeners(AuditingEntityListener.class)
public class TimeInfo extends BaseEntity {

	/**
	 * 
	 */
	@Column(columnDefinition = " INT(10) COMMENT ''")
	private Integer version;

	/**
	 * 时段名称
	 */
	@Column(columnDefinition = " VARCHAR(64) COMMENT '时段名称'")
	private String name;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String sunTime1;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String sunTime2;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String sunTime3;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String monTime1;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String monTime2;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String monTime3;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String tueTime1;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String tueTime2;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String tueTime3;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String wedTime1;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String wedTime2;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String wedTime3;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String thuTime1;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String thuTime2;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String thuTime3;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String friTime1;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String friTime2;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String friTime3;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String satTime1;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String satTime2;

	/**
	 * 
	 */
	@Column(columnDefinition = " VARCHAR(100) COMMENT ''")
	private String satTime3;

	@Override
	public String toString() {
		return  "TimezoneId=" + getId() + "\t" +
		        "SunTime1=" + transforTime(sunTime1) + "\t" +
				"SunTime2=" + transforTime(sunTime2) + "\t" +
				"SunTime3=" + transforTime(sunTime3) + "\t" +
				"MonTime1=" + transforTime(monTime1) + "\t" +
				"MonTime2=" + transforTime(monTime2) + "\t" +
				"MonTime3=" + transforTime(monTime3) + "\t" +
				"TueTime1=" + transforTime(tueTime1) + "\t" +
				"TueTime2=" + transforTime(tueTime2) + "\t" +
				"TueTime3=" + transforTime(tueTime3) + "\t" +
				"WedTime1=" + transforTime(wedTime1) + "\t" +
				"WedTime2=" + transforTime(wedTime2) + "\t" +
				"WedTime3=" + transforTime(wedTime3) + "\t" +
				"ThuTime1=" + transforTime(thuTime1) + "\t" +
				"ThuTime2=" + transforTime(thuTime2) + "\t" +
				"ThuTime3=" + transforTime(thuTime3) + "\t" +
				"FriTime1=" + transforTime(friTime1) + "\t" +
				"FriTime2=" + transforTime(friTime2) + "\t" +
				"FriTime3=" + transforTime(friTime3) + "\t" +
				"SatTime1=" + transforTime(satTime1)+ "\t" +
				"SatTime2=" + transforTime(satTime2) + "\t" +
//				"Hol1Time1=" + transforTime(satTime3)+ "\t" +
//				"Hol1Time2=" + transforTime(satTime3)+ "\t" +
//				"Hol1Time2=" + transforTime(satTime3)+ "\t" +
//				"Hol2Time1=" + transforTime(satTime3)+ "\t" +
//				"Hol2Time2=" + transforTime(satTime3)+ "\t" +
//				"Hol2Time3=" + transforTime(satTime3)+ "\t" +
//				"Hol3Time1=" + transforTime(satTime3)+ "\t" +
//				"Hol3Time2=" + transforTime(satTime3)+ "\t" +
//				"Hol3Time3=" + transforTime(satTime3)+ "\t" +
				"SatTime3=" + transforTime(satTime3);
	}

	public String transforTime(String time) {
		String result = "";
		if (StringUtils.isNotEmpty(time)) {
			String[] timeStr = time.trim().split(" ~ ");
//			String[] timeAll1 = timeStr[0].split(":");
//			String timeHour1 = timeAll1[0].replaceFirst("0","");
//			String timeHour1 = timeAll1[0];
//			String timeMinu1 = timeAll1[1];
//			String[] timeAll2 = timeStr[1].split(":");
////			String timeHour2 = timeAll2[0].replaceFirst("0","");
//			String timeHour2 = timeAll2[0];
//			String timeMinu2 = timeAll2[1];
			Integer time1 = Integer.parseInt(timeStr[0].replace(":",""));
			Integer time2 =   Integer.parseInt(timeStr[1].replace(":",""));
			result = ((time1 << 16) + time2)+"";
		}
		return result;
	}
}
